﻿using System;
using NUnit.Framework;

namespace ExtensionMethodExtravaganza.Tests
{
	[TestFixture]
	public class ObjectExtensionsTests
	{
		[Test]
		public void AsTest()
		{
			var o = new object();
			var person = o.As<Person, Manager, Employee>();

			Assert.IsNull(person);

			o = new Manager();
			person = o.As<Person, Manager, Employee>();

			Assert.IsNotNull(person);

			o = new Employee();
			person = o.As<Person, Manager, Employee>();

			Assert.IsNotNull(person);
		}

		[Test]
		public void IsTest()
		{
			var m = new Manager();

			Assert.IsTrue(m.Is<Manager,Company>(), "Same type and invalid type");
			Assert.IsTrue(m.Is<Person,Company>(), "Supertype and invalid type"); 
			Assert.IsFalse(m.Is<String,Company>(), "Two invalid types");
		}

		[Test]
		public void CreateArrayTest()
		{
			var o = new object();
			var a = o.CreateArray();

			Assert.AreEqual(1, a.Length);
			Assert.AreSame(o, a[0]);
		}
	}
}
